"""
【抽实分离  抽湿分离】
桥接模式(Bridge Pattern)：将抽象部分和实现部分分离开，以便它们可以独立地变化。
该模式使用组合的方式将抽象和实现部分连接。
例如，在游戏中有多种武器和角色，我们可以使用桥接模式将武器和角色分离开来，从而可自由地组合它们
"""


class Weapon:
    def __init__(self, name):
        self.name = name


class Sword(Weapon):
    def attack(self):
        print(f"{self.name} is attacking with sword!")


class Bow(Weapon):
    def attack(self):
        print(f"{self.name} is attacking with bow!")


class Character:
    def __init__(self, name, weapon):
        self.name = name
        self.weapon = weapon

    def attack(self):
        self.weapon.attack()


class Warrior(Character):
    pass


class Mage(Character):
    pass


sword = Sword("Excalibur")
bow = Bow("Robin Hood's Bow")
warrior = Warrior("Arthur", sword)
mage = Mage("Merlin", bow)

warrior.attack()  # Arthur is attacking with sword!
mage.attack()  # Merlin is attacking with bow!
